// 导入 axios
import axios from '@/utils/request.js'

// 按需 导出 获取新token方法----------------------------------
export const refreshToken = (refreshToken) => axios({
  url: '/v1_0/authorizations',
  method: 'put',
  headers: { // 发送 用来更新的 token 到服务器
    Authorization: 'Bearer ' + refreshToken
  }
})

// 1.登录方法---------------------------------
export const login = (mobile, code) => {
  return axios({
    method: 'post',
    url: '/v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}

// 2.获取短信验证码方法-------------------------
export const getSmsCode = (mobile) => {
  return axios({
    method: 'get',
    url: `/v1_0/sms/codes/${mobile}`
  })
}

// 3.获取用户完整信息----------------------------
export const getUsrInfo = () => {
  return axios({
    method: 'get',
    url: '/v1_0/user'
    // headers: {
    //   Authorization: 'Bearer' + store.state.user
    // }
  })
}

// 4.获取登录用户资料----------------------------
export const getProfile = () => {
  return axios({
    method: 'get',
    url: '/v1_0/user/profile'
  })
}

// 5.修改用户资料---------------------------------
export const updateUser = ({ name, gender, birthday }) => {
  return axios({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data: {
      name,
      gender,
      birthday
    }
  })
}

// 6.修改用户头像---------------------------------
export const updatePhoto = (fd) => {
  return axios({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data: fd
  })
}
